package sort;

import java.util.Arrays;
import java.util.Random;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * User:Mr.Du
 * Date:2020/11/10
 * Time:0:14
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] arr = new int[10];
        Random r = new Random();

        for(int ii = 0;ii<10;ii++){
            for(int i = 0;i<arr.length;i++){
                arr[i] = r.nextInt(50);
            }
            bubbleSort(arr);
            System.out.println(Arrays.toString(arr));
        }

    }

    private static void bubbleSort(int[] arr) {
        for(int i =1;i<arr.length;i++){
            for(int j = 0;j<arr.length - i;j++){
                if(arr[j]>arr[j+1]){
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
    }
}
